package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.StudentBean;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("student")
public class StudentController {
    @Autowired
    private IStudentService service;

    @RequestMapping("cutAll")
    public String  cutAll(Integer pageNO, HttpServletRequest req){
        if(pageNO == null){
            pageNO = 1;
        }

        IPage<StudentBean> ip = service.cutAll(pageNO);
        req.setAttribute("cutObj",ip);
        return "/index.html";
    }

    @RequestMapping("add")
    public String add(StudentBean student){
        service.add(student);
        return "redirect:/student/cutAll";
    }

    @RequestMapping("del")
    public String del(Integer id){
        service.del(id);
        return "redirect:/student/cutAll";
    }

    @RequestMapping("findById")
    public String findById(Integer id,HttpServletRequest req){
        StudentBean student = service.findById(id);
        req.setAttribute("studentObj",student);
        return "/update.html";
    }

    @RequestMapping("update")
    public String update(Integer id,String edu){
        service.update(id,edu);
        return "redirect:/student/cutAll";
    }
}
